package itheima_05;
//Calendar常用方法

import java.util.Calendar;

public class CalendarDemo {
    public static void main(String[] args) {
        Calendar c = Calendar.getInstance();//多态的形式，实际是子子类对象
        System.out.println(c);
        System.out.println("------------");
        //常用方法1：
        int year = c.get(Calendar.YEAR);
        int month = c.get(Calendar.MONTH) + 1;//从零开始的，所以要加1
        int date = c.get(Calendar.DATE);
        System.out.println(year + "年" + month + "月" + date + "日");
        System.out.println("----------------------");
        //常用方法2：
        c.add(Calendar.YEAR, -3);//需求1:三年前的今天
        c.add(Calendar.DATE, -5);//需求2：五天前
        int year2 = c.get(Calendar.YEAR);
        int month2 = c.get(Calendar.MONTH) + 1;//从零开始的，所以要加1
        int date2 = c.get(Calendar.DATE);
        System.out.println(year2 + "年" + month2 + "月" + date2 + "日");
        System.out.println("-----------------");
        //常用方法3:
        c.set(2022, 0, 30);//月份从零开始，0代表1月
        int year3 = c.get(Calendar.YEAR);
        int month3 = c.get(Calendar.MONTH) + 1;//从零开始的，所以要加1
        int date3 = c.get(Calendar.DATE);
        System.out.println(year3 + "年" + month3 + "月" + date3 + "日");

    }
}
